package com.geo.content.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.geo.content.entity.MultimodalContent;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 多模态内容Mapper接口
 */
@Mapper
public interface MultimodalContentMapper extends BaseMapper<MultimodalContent> {
    
    /**
     * 根据用户ID查询内容列表
     */
    @Select("SELECT * FROM multimodal_content WHERE user_id = #{userId} AND deleted = 0 ORDER BY created_at DESC")
    List<MultimodalContent> findByUserId(@Param("userId") String userId);
    
    /**
     * 根据内容类型查询
     */
    @Select("SELECT * FROM multimodal_content WHERE content_type = #{contentType} AND deleted = 0")
    List<MultimodalContent> findByContentType(@Param("contentType") String contentType);
    
    /**
     * 根据状态查询内容
     */
    @Select("SELECT * FROM multimodal_content WHERE status = #{status} AND deleted = 0")
    List<MultimodalContent> findByStatus(@Param("status") String status);
    
    /**
     * 根据关键词查询内容
     */
    @Select("SELECT * FROM multimodal_content WHERE JSON_CONTAINS(keywords, JSON_QUOTE(#{keyword})) AND deleted = 0")
    List<MultimodalContent> findByKeyword(@Param("keyword") String keyword);
    
    /**
     * 更新内容状态
     */
    @Update("UPDATE multimodal_content SET status = #{status}, updated_at = NOW() WHERE id = #{contentId}")
    int updateStatus(@Param("contentId") String contentId, @Param("status") String status);
    
    /**
     * 增加浏览次数
     */
    @Update("UPDATE multimodal_content SET view_count = view_count + 1 WHERE id = #{contentId}")
    int incrementViewCount(@Param("contentId") String contentId);
    
    /**
     * 根据时间范围查询内容
     */
    @Select("SELECT * FROM multimodal_content WHERE created_at >= #{startTime} AND created_at <= #{endTime} AND deleted = 0")
    List<MultimodalContent> findByTimeRange(@Param("startTime") LocalDateTime startTime, 
                                           @Param("endTime") LocalDateTime endTime);
    
    /**
     * 查询热门内容
     */
    @Select("SELECT * FROM multimodal_content WHERE deleted = 0 ORDER BY view_count DESC LIMIT #{limit}")
    List<MultimodalContent> findPopularContent(@Param("limit") int limit);
    
    /**
     * 根据质量分数查询内容
     */
    @Select("SELECT * FROM multimodal_content WHERE quality_score >= #{minScore} AND deleted = 0 ORDER BY quality_score DESC")
    List<MultimodalContent> findByQualityScore(@Param("minScore") Double minScore);
}